<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>Doxygen manual for MemAlloc: The mainpage for MemAlloc interface by Oleg</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Doxygen manual for MemAlloc
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">The mainpage for <a class="el" href="classMemAlloc.html" title="Memory Allocator interface class.">MemAlloc</a> interface by Oleg </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>ATTENTION, C++11</p>
<p>Please, look at this documentation in generated html or latex files.</p>
<p>Several words about how to implement this interface.</p>
<p>First of all, why didn't I write usual interface with virtual functions? Answer is quite simple: MemoryAllocator uses template methods but template methods are not allowed to be virtual in C++.</p>
<p>So the only way to separate interface from realization is to use one special pointer in private section named Impl and pass concreate realization class via constructor. In the interface file we use forward-declaration to declare Implementation classes so interfaces file is self-sufficient to include it into every project part. As you can see, our goal is reached. This file contains only interfaces without realization. This method is widely-used and called pimpl-idiom (<a href="http://www.gotw.ca/gotw/024.htm,">http://www.gotw.ca/gotw/024.htm,</a> <a href="http://www.gotw.ca/gotw/028.htm">http://www.gotw.ca/gotw/028.htm</a>). And now several words about how realization file should be structured. One should write realization for all classes and their Impl parts.</p>
<p><a class="el" href="classMemAlloc.html" title="Memory Allocator interface class.">MemAlloc</a> is a singleton. It's your care how to implement singleton but method Init should construct it and static method Deinit - destroy. When <a class="el" href="classMemAlloc.html" title="Memory Allocator interface class.">MemAlloc</a> object is constructed one should use method Instance to get refference for it. Constructor of <a class="el" href="classMemAlloc.html" title="Memory Allocator interface class.">MemAlloc</a> is private because it's supposed to be called only from Init function. And small attention. BE VERY VERY CAREFULL WHEN USING SMP SINGLETON. (I advice you to read this small article <a href="http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf">http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf</a>)</p>
<p>And now about <a class="el" href="classSmartPtr.html" title="SMartPtr interface class.">SmartPtr</a>. As you can see it has public constructor which takes pointer to <a class="el" href="classSmartPtrImpl.html">SmartPtrImpl</a> class. But it's critical for us to allow a <a class="el" href="classSmartPtr.html" title="SMartPtr interface class.">SmartPtr</a> construction only for Memory Allocator. But we take it automatically because nobody has declaration of <a class="el" href="classSmartPtrImpl.html">SmartPtrImpl</a>. Logically <a class="el" href="classSmartPtrImpl.html">SmartPtrImpl</a> and MemAllocImpl are two parts of the same mechanise called Memory allocator so they should be friends of each other. Thus only MemAllocIMpl will be able to construct SmartPointers.</p>
<p>And finally about exception handling policy. I decided to handle all errors using exceptions. Thus dynamic memory errors will throw std::bad_alloc exception, all problems with swap file will throw std::ios_base::failure exceptions. Stop. One moment If you want ofstream behave this way you should manually set it's exception policy flags (<a href="http://www.cplusplus.com/reference/ios/ios/exceptions/">http://www.cplusplus.com/reference/ios/ios/exceptions/</a>).</p>
<p>Thank you for your reading. I will be happy to answer all your questions and listen to your proposals.</p>
<p>Oleg <a href="#" onclick="location.href='mai'+'lto:'+'onp'+'on'+'oma'+'re'+'v@g'+'ma'+'il.'+'co'+'m'; return false;">onpon<span style="display: none;">.nosp@m.</span>omar<span style="display: none;">.nosp@m.</span>ev@gm<span style="display: none;">.nosp@m.</span>ail.<span style="display: none;">.nosp@m.</span>com</a> </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Mon Apr 7 2014 12:04:10 for Doxygen manual for MemAlloc by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.3.1
</small></address>
</body>
</html>
